package cn.schoolwow.ams.module.block.listBlock.clazzBlock.api.flow;

import cn.schoolwow.ams.domain.block.list.clazz.crud.ClazzListBlockUpdateListener;
import cn.schoolwow.ams.module.block.listBlock.clazzBlock.initial.domain.ClazzListBlockContext;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import com.alibaba.fastjson.JSONObject;

public class ExecuteClazzListBlockUpdateListenerFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String projectName = (String) flowContext.checkData("projectName");
        String clazzName = (String) flowContext.checkData("clazzName");
        ClazzListBlockContext clazzListBlockContext = flowContext.checkInstanceData(ClazzListBlockContext.class);
        JSONObject requestBody = flowContext.checkData("requestBody", JSONObject.class);

        ClazzListBlockUpdateListener clazzListBlockUpdateListener = clazzListBlockContext.clazzListBlockAPIListener.updateListener;
        if(null== clazzListBlockUpdateListener){
            throw new IllegalArgumentException("当前列表未配置编辑记录处理器!项目名:"+projectName+",clazz名称:"+clazzName);
        }
        clazzListBlockUpdateListener.update(requestBody);
    }

    @Override
    public String name() {
        return "执行ClazzListBlock类型的编辑逻辑";
    }

}
